﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;

namespace PacManPP.Managers
{
    class SoundManager
    {
     
        static ContentManager content;

        static public SoundEffect dotSound;
        static public SoundEffect start;
        static public SoundEffect dead;

        static SoundEffectInstance dotSoundInstance;
        static SoundEffectInstance startSoundInstance;
        static SoundEffectInstance deadSoundInstance;

        public static ContentManager contentManager
        {
            get { return SoundManager.content; }
            set { SoundManager.content = value;}
        }

        public static void LoadContent()
        {
            dotSound = content.Load<SoundEffect>("pacman_chomp");
            dotSoundInstance = dotSound.CreateInstance();

            start = content.Load<SoundEffect>("pacman_beginning");
            startSoundInstance = start.CreateInstance();

            dead = content.Load<SoundEffect>("pacman_death");
            deadSoundInstance = dead.CreateInstance();
        }

        public static void PlayDotSound()
        {
            if (dotSoundInstance.State == SoundState.Playing)
                dotSoundInstance.Stop();

            dotSoundInstance = dotSound.CreateInstance();
            dotSoundInstance.Volume = 1.0f;
            dotSoundInstance.IsLooped = false;
            dotSoundInstance.Play();
        }

        public static void StartSound()
        {
            if (startSoundInstance.State == SoundState.Playing)
                startSoundInstance.Stop();

            startSoundInstance = start.CreateInstance();
            startSoundInstance.Volume = 1.0f;
            startSoundInstance.IsLooped = false;
            startSoundInstance.Play();
        }

        public static void DeadSound()
        {
            if (deadSoundInstance.State == SoundState.Playing)
                deadSoundInstance.Stop();

            deadSoundInstance = dead.CreateInstance();
            deadSoundInstance.Volume = 1.0f;
            deadSoundInstance.IsLooped = false;
            deadSoundInstance.Play();
        }

    }
}
